/* File Info 
 * Author:      李佳乐 
 * CreateTime:  2023/12/26 15:15:58 
 * LastEditor:  李佳乐 
 * ModifyTime:  2023/12/26 15:22:38 
 * Description: 转换函数，即在使用类的对象时，可以自动将对象转换为某种特定类型， operator double() const;
*/ 
#include <iostream>

using namespace std;

class fraction
{
public:
    fraction(const int &a, const int &b) : up(a), down(b){};
    operator double() const;

private:
    int up;
    int down;
};

fraction::operator double() const
{
    return ((double)up) / ((double)down);
}

int main() {
    fraction a(3,2);
    double b = 1 + a;
    cout <<"b = "<<b<<endl;
    system("pause");
}